package cn.seaboot.admin.user.web;

import cn.seaboot.admin.mvc.Pagination;
import cn.seaboot.admin.mvc.argument.Params;
import cn.seaboot.admin.user.bean.Organization;
import cn.seaboot.admin.user.service.OrganizationService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 组织机构 [t_sys_org] - Controller
 * <p>
 *
 * @author Mr.css on 2018-6-20
 */
@Controller
@RequestMapping("sys/org")
@Tag(name = "组织机构 [t_sys_org] 管理")
public class OrganizationCtrl {

    @Resource
    private OrganizationService tOrgService;


    /**
     * 增
     *
     * @param pojo pojo
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "组织机构 [t_sys_org] 增")
    @RequestMapping(value = "info", method = RequestMethod.POST)
    public int saveInfo(@Validated Organization pojo) {
        return tOrgService.insert(pojo);
    }

    /**
     * 删
     *
     * @param id id
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "组织机构 [t_sys_org] 删")
    @RequestMapping(value = "info", method = RequestMethod.DELETE)
    public int deleteInfo(@Params String id) {
        return tOrgService.deleteById(id);
    }

    /**
     * 查
     *
     * @param id id
     * @return pojo
     */
    @ResponseBody
    @Operation(description = "组织机构 [t_sys_org] 查")
    @RequestMapping(value = "info", method = RequestMethod.GET)
    public Organization queryById(@Params String id) {
        return tOrgService.queryById(id);
    }

    /**
     * 改
     *
     * @param pojo pojo
     * @return affected rows
     */
    @ResponseBody
    @Operation(description = "组织机构 [t_sys_org] 改")
    @RequestMapping(value = "info", method = RequestMethod.PUT)
    public int updateInfo(@Params String id, @Validated Organization pojo) {
        return tOrgService.updateById(pojo);
    }

    /**
     * 查列表
     *
     * @param params 参数
     * @return PageInfo
     */
    @ResponseBody
    @Operation(description = "组织机构 [t_sys_org] 列表查询")
    @Parameters({
            @Parameter(name = "page", description = "页号"),
            @Parameter(name = "limit", description = "行数")})
    @RequestMapping(value = "page", method = RequestMethod.GET)
    public PageInfo<Organization> queryPage(@RequestParam Map<String, Object> params) {
        return Pagination.apply(params, map-> tOrgService.queryList(map));
    }
}

